﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Form : MonoBehaviour
{
    private Camera rteCamera;
    private InputField inputField;
    private Button btn;

    //业务相关 按钮
    private Transform addAreaBtn;
    private Transform delAreaBtn;
    private Transform content;
    private Transform drawAnchorBtn;
    private Transform drawAreaBtn;
    private Transform exitDrawBtn;

    //预制体
    private GameObject childArea;


    // Start is called before the first frame update
    void Start()
    {
        rteCamera = RTEditor.EditorCamera.Instance.gameObject.GetComponent<Camera>();
        addAreaBtn = transform.Find("ConfigAreaPanel/AddAreaBtn");
        delAreaBtn = transform.Find("ConfigAreaPanel/DelAreaBtn");
        drawAnchorBtn = transform.Find("DrawAnchorBtn");
        drawAreaBtn = transform.Find("DrawAreaBtn");
        exitDrawBtn = transform.Find("ExitDrawBtn");
        content = transform.Find("ConfigAreaPanel/AreaPanel/Viewport/Content");

        addAreaBtn.GetComponent<Button>().onClick.AddListener(AddAreaBtn_Click);
        delAreaBtn.GetComponent<Button>().onClick.AddListener(DelAreaBtn_Click);
        EventTriggerListener.Get(drawAnchorBtn).onClick += DrawAnchorBtn_Click;
        EventTriggerListener.Get(drawAnchorBtn).onClick += DrawAreaBtn_Click;
        EventTriggerListener.Get(exitDrawBtn).onClick += ExitDrawBtn_Click;

        childArea = Resources.Load<GameObject>("ChildArea");

        AddAreaBtn_Click();//默认添加一个区域
    }

    private void ExitDrawBtn_Click(GameObject go)
    {
        AnchorManager.Instance.OpenGenAnchorFunc(false);
    }

    private void DrawAreaBtn_Click(GameObject go)
    {
        
    }

    private void DrawAnchorBtn_Click(GameObject go)
    {
        AnchorManager.Instance.OpenGenAnchorFunc(true);
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    //public void GenerateCube()
    //{
    //    GameObject go = Instantiate(cube);
    //    Vector3 pos = rteCamera.ScreenToWorldPoint(new Vector3(Screen.width / 2, Screen.height / 2, 10f));
    //    go.transform.position = pos;
    //    RTEditor.EditorObjectSelection.Instance.ClearSelection(true);
    //    RTEditor.EditorObjectSelection.Instance.AddObjectToSelection(go, true);
    //}

    //public void GenerateSphere()
    //{
    //    GameObject go = Instantiate(sphere);
    //    Vector3 pos = rteCamera.ScreenToWorldPoint(new Vector3(Screen.width / 2, Screen.height / 2, 10f));
    //    go.transform.position = pos;
    //    RTEditor.EditorObjectSelection.Instance.ClearSelection(true);
    //    RTEditor.EditorObjectSelection.Instance.AddObjectToSelection(go, true);
    //}


    private void AddAreaBtn_Click()
    {
        Instantiate(childArea, content);
    }

    private void DelAreaBtn_Click()
    {
        int count = content.childCount;
        if (count > 1)
        {
            Destroy(content.GetChild(count - 1).gameObject);
        }
    }

}
